﻿using AutoRegistDependency.Attributes;
using Core.ApiFilter.Attributes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Services.Log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi.Middlewares.Attributes;

namespace WebApi.Controllers
{
	[Component]
	[Authorize]
    [IgnoreLog]
	[ApiController]
	[Route("api/[controller]")]
	[ApiExplorerSettings(GroupName = "base_api")]
	public class LogController : ControllerBase
    {
        private ILogService logService;
        public LogController(ILogService logService)
        {
            this.logService = logService;
        }
        /// <summary>
        /// 获取日志数据
        /// </summary>
        /// <param name="StartTime">开始日期</param>
        /// <param name="EndTime">结束日期</param>
        /// <param name="Method">请求方式</param>
        /// <param name="ControllerName">控制器名称</param>
        /// <param name="Action">动作名称</param>
        /// <param name="page">页码</param>
        /// <param name="limit">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetLogInfo(DateTime? StartTime,DateTime? EndTime,string Method,string ControllerName,string Action, int page, int limit)
        {
            return Ok(logService.GetOrderbyInfoByPage(StartTime, EndTime, Method, ControllerName, Action, page, limit));
        }
        /// <summary>
        /// 获取项目内未标记不记录日志特性的控制器信息
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("GetControllerName")]
        public IActionResult GetControllerName() => Ok(logService.GetControllerName());
    }
}
